package com.aoxin.controller.client;

import java.util.List;
import java.util.Map;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import com.aoxin.service.inter.client.EpOrderService;
import com.aoxin.util.AjaxRes;
import com.aoxin.util.Const;

@RestController()
@RequestMapping("/web/epOrder/")
public class EpOrderController {
	@Autowired
	private EpOrderService epOrderService;

	/**
	 * 查询最近一条课程表记录
	 * 
	 * @return
	 */
	@RequestMapping("checkLastOneCourse")
	public AjaxRes checkLimitCourse(AjaxRes ajaxRes,String startDate) {
		try {
			List<Map<String, Object>> courseOrPageData = epOrderService.checkLimitCourse(startDate);
			ajaxRes.setSucceed(courseOrPageData, Const.DATA_SUCCEED);
		} catch (Exception e) {
			ajaxRes.setFailMsg(e.getMessage());
		}
		return ajaxRes;
	}

	/**
	 * 修改课程表状态(取消,排队中,即将开始上课)
	 * 
	 * @param state
	 * @param id
	 * @return
	 */
	@RequestMapping("updateState")
	public AjaxRes updateState(String state, Integer id, AjaxRes ajaxRes) {
		try {
			epOrderService.updateState(state, id);
			ajaxRes.setSucceed(Const.UPDATE_SUCCEED);
		} catch (Exception e) {
			ajaxRes.setFailMsg(e.getMessage());
		}
		return ajaxRes;
	}

	/**
	 * 根据B类课程ID插入到课程表
	 * 
	 * @param courseId
	 * @return
	 */
	@RequestMapping("addEPOrder")
	public AjaxRes addEPOrder(Integer courseId, AjaxRes ajaxRes) {
		try {
			Integer integer = epOrderService.addEPOrder(courseId);
			if (integer > 0) {
				ajaxRes.setSucceed(Const.SAVE_SUCCEED);
			} else {
				ajaxRes.setSucceed(Const.SAVE_FAIL);
			}
		} catch (Exception e) {
			ajaxRes.setFailMsg(e.getMessage());
		}
		return ajaxRes;
	}
}
